/*
 * DBPool.cpp
 *
 *  Created on: Aug 12, 2016
 *      Author: ubuntu
 */

#include "DBPool.h"

DBPool::DBPool(const char *dbname, const char *host, const char *user, const char *pass, int port) :
	m_db(dbname), m_host(host), m_user(user), m_pass(pass), m_port(port)
{
}

DBPool::~DBPool()
{
	clear();
}

Connection *DBPool::create()
{
	Connection *conn = new Connection(true);
	conn->connect(m_db.c_str(), m_host.c_str(), m_user.c_str(), m_pass.c_str(), m_port);
	Query query = conn->query();
	query << "set names utf8";
	query.exec();
	return conn;
}

void DBPool::destroy(Connection *conn)
{
	delete conn;
}

unsigned int DBPool::max_idle_time()
{
	return 30; // 30秒
}
